<cfcomponent name="SVGMunger" namespace="com.nowrists">
	<cffunction name="init" access="public" output="false" returntype="SVGMunger">
		<cfargument name="Filename" type="string" required="true">
		<cfset var FileContent="">
		<!--- <cftry> --->
			<cffile action="read" variable="FileContent" file="#Arguments.Filename#">
			<cfset this.XML=XMLParse(FileContent)>
			<cfset this.Filename=Arguments.Filename>
		<!--- <cfcatch>
			<cfset this.ErrorMessage=CFCatch.Message>
			<cfset this.ErrorDetail=CFCatch.Detail>
		</cfcatch>
		</cftry> --->
		<cfreturn this>
	</cffunction>
	<cffunction name="SaveAs" access="public" output="false" returntype="boolean">
		<cfargument name="Filename" type="string" required="true">
		<cfset XmlAsString=Replace(ToString(this.XML),"UTF-8","ISO-8859-1","ONE")>
		<cftry>
			<cffile action="write" output="#XmlAsString#" file="#Arguments.FileName#" charset="iso-8859-1">
		<cfcatch>
			<cfset this.ErrorMessage=CFCatch.Message>
			<cfset this.ErrorDetail=CFCatch.Detail>
			<cfreturn false>
		</cfcatch>
		</cftry>
		<cfreturn true>
	</cffunction>
	<cffunction name="ReplaceIdContent" access="public" output="false" returntype="numeric">
		<cfargument name="id" type="string" required="true">
		<cfargument name="NewContent" type="string" required="true">
		<cfset var el=XmlSearch(this.XML,"/descendant::*[attribute::id='#Arguments.id#']")>
		<cfset var i=0>
		<cfif Arguments.NewContent EQ ""><cfset Arguments.NewContent=" "></cfif>
		<cfloop from="1" to="#ArrayLen(el)#" index="i">
			<cfset el[i].XmlText=Arguments.NewContent>
			<cfset ArrayClear(el[i].XmlChildren)>
		</cfloop>
		<cfreturn ArrayLen(el)>
	</cffunction>
	<cffunction name="ReplaceIdAttribute" access="public" output="false" returntype="numeric">
		<cfargument name="id" type="string" required="true">
		<cfargument name="AttributeName" type="string" required="true">
		<cfargument name="NewContent" type="string" required="true">
		<cfset var el=XmlSearch(this.XML,"/descendant::*[attribute::id='#Arguments.id#']")>
		<cfset var i=0>
		<cfloop from="1" to="#ArrayLen(el)#" index="i">
			<cfset el[i].XmlAttributes[Arguments.AttributeName]=Arguments.NewContent>
		</cfloop>
		<cfreturn ArrayLen(el)>
	</cffunction>
</cfcomponent>